package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface MenuMapper extends BaseMapper<Menu> {
    // 用于获取菜单 其中的一个步骤
    @Select("select tr.id from t_user tu,t_role tr where tu.username = #{username} and tu.id = tr.id ")
    List<Integer> findRoleIdsByUsername(String username);

    @Select("select tm.id,tm.path,tm.name,tm.icon from t_role_menu trm,t_menu tm where trm.menu_id = tm.id and tm.parentMenuId is null and trm.role_id = #{roleId}")
    Set<Menu> findMenusByRoleId(Integer roleId);

    @Select("select tm.path,tm.name,tm.linkUrl from t_role_menu trm,t_menu tm where trm.menu_id = tm.id and trm.role_id = #{roleId} and tm.parentMenuId = #{menuId}")
    List<Menu> findChildrenMenus(@Param("roleId") Integer roleId,@Param("menuId") Integer menuId);
}
